//

//  health
//
//  Created by apple on 2021/11/9.
//  Copyright © 2021 zglee. All rights reserved.
//

#import "MJTotalCholesterolModel.h"
#import <WCDBObjc/WCDBObjc.h>
@implementation MJTotalCholesterolModel

WCDB_IMPLEMENTATION(MJTotalCholesterolModel) //使用WCDB_IMPLEMENTATION宏在类文件定义绑定到数据库表的类。 该宏实现绑定到表

WCDB_SYNTHESIZE(detectionId)
WCDB_SYNTHESIZE(userId)
WCDB_SYNTHESIZE(userName)
WCDB_SYNTHESIZE(patientId)
WCDB_SYNTHESIZE(patientName)
WCDB_SYNTHESIZE(age)
WCDB_SYNTHESIZE(gender)
WCDB_SYNTHESIZE(detectionDateTime)
WCDB_SYNTHESIZE(createDateTime)
WCDB_SYNTHESIZE(period)
WCDB_SYNTHESIZE(orgName)
WCDB_SYNTHESIZE(isMultiple)

WCDB_SYNTHESIZE(totalCholesterol)
WCDB_SYNTHESIZE(risk)
WCDB_SYNTHESIZE(evaluation)
WCDB_SYNTHESIZE(unit)

WCDB_PRIMARY(detectionId)

- (void)switchUnit {
    if([self.unit isEqualToString:unitmgdL]){
        self.unit = unitmmolL;
        self.totalCholesterol = self.totalCholesterol/38.66;
    }else{
        self.unit = unitmgdL;
        self.totalCholesterol = self.totalCholesterol*38.66;
    }
}

- (BOOL)showArrowsUp {
//    return self.gradeValue > 0 ? true:false;
    
    if([self.unit isEqualToString:unitmgdL]){
        if(_totalCholesterol >= 201){
            return true;
        }
    }else{
        if(_totalCholesterol >= 5.2){
            return true;
        }
    }
    return false;
}

- (NSString *)totalCholesterolString {
    if([self.unit isEqualToString:unitmgdL]){
        NSString *value;
        if (_totalCholesterol == 0) {
            value = @"--";
        }else if (_totalCholesterol<19){
            value = @"Lo";
        }else if (_totalCholesterol>387){
            value = @"Hi";
        }else{
            value = [NSString mj_stringWithCGFloat:_totalCholesterol decimal:0];
        }
        return value;
    }else{
        NSString *value;
        if (_totalCholesterol == 0) {
            value = @"--";
        }else if (_totalCholesterol<0.50){
            value = @"Lo";
        }else if (_totalCholesterol>10.0){
            value = @"Hi";
        }else{
            value = [NSString mj_stringWithCGFloat:_totalCholesterol decimal:2];
        }
        return value;
    }
}

- (NSInteger)gradeValue {
    if([self.risk isEqualToString:@"Low"]){
        return 0;
    }else if([self.risk isEqualToString:@"Moderate"]){
        return 1;
    }else if([self.risk isEqualToString:@"High"]){
        return 2;
    }else if([self.risk isEqualToString:@"VeryHigh"]){
        return 3;
    }else{
        return 0;
    }
}

- (NSString *)evaluationString {
    return [@"TotalCholesterol.evaluation." stringByAppendingString:_evaluation];
}

- (NSString *)differenceValue {
    NSString *value;
    if([self.unit isEqualToString:unitmgdL]){
        value = [NSString mj_stringWithCGFloat:self.totalCholesterol - 200 decimal:0];
    }else{
        value = [NSString mj_stringWithCGFloat:self.totalCholesterol - 5.19 decimal:2];
    }
    return [NSString stringWithFormat:@"-%@",value];
}
- (NSString *)standardValue {
    if([self.unit isEqualToString:unitmgdL]){
        return @(200).description;
    }else{
        return @(5.19).description;
    }
}

@end

